package com.ly.rabbitmq.spring;

import com.ly.rabbitmq.config.RabbitMQConfig;
import lombok.AllArgsConstructor;
import lombok.Data;

import org.junit.jupiter.api.Test;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Component;
import org.springframework.test.context.junit4.SpringRunner;


/**
 * @Classname Product
 * @Description TODO
 * @Date 2020/11/20 20:29
 * @Author 冷心影翼
 */


//@Component
public class Producer {

	@Autowired
	private RabbitTemplate rabbitTemplate;

	public void send() {
		MessageData testData = new MessageData("1",22,new MessageData("2",33,null));
		rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_NAME,"hello.error",testData);
	}


	public void sendTTL() {
		MessagePostProcessor messagePostProcessor = message -> {
			message.getMessageProperties().setExpiration("5000");
			return message;
		};
		MessageData testData = new MessageData("1",22,new MessageData("2",33,null));
		rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_NAME,"ttl.warn",testData,messagePostProcessor);
	}


}
